package com.example.administrator.fangbook.HtlMvp.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.example.administrator.fangbook.HtlMvp.activity.BaseMvpPresenter;
import com.example.administrator.fangbook.HtlMvp.activity.BaseMvpView;
import com.example.administrator.fangbook.base.BaseActivity;
import com.example.administrator.fangbook.base.BaseFragment;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/11/9.
 */

public abstract class BaseMvpFragment<V extends BaseMvpView, P extends BaseMvpPresenter> extends BaseFragment {

    private V mMvpView;
    private P mMvpPresenter;

    @SuppressWarnings("unchecked")
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        this.mMvpView = bindMvpView();
        if (this.mMvpPresenter == null) {
            this.mMvpPresenter = bindMvpPresenter();
        }
        this.mMvpPresenter.attachView(this.mMvpView);
        super.onCreate(savedInstanceState);
    }

    protected abstract P bindMvpPresenter();

    protected abstract V bindMvpView();
    public P getmMvpPresenter() {
        return mMvpPresenter;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initFragment(getArguments());
    }

    protected abstract void initFragment(Bundle arguments);

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mMvpPresenter.destroyView();
        this.mMvpPresenter = null;
    }
}
